package com.zxf.appliction.service.impl;

import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.SetOperations;
import org.springframework.data.redis.core.ValueOperations;

public class TestSringDataJedis {
	  static RedisTemplate redisTemplate;


	    public void set(String key,Object value){
	        //ValueOperations 理解成Map<Object,Object>


	        ValueOperations valueOperations = redisTemplate.opsForValue();
	        valueOperations.set(key,value);


	        //BoundValueOperations的理解对保存的值做一些细微的操作
	    }
	    public Object get(String key){
	        return redisTemplate.opsForValue().get(key);
	    }
	    public void setList(String key ,List<?> value){
	        //ListOperations可以理解为List<Object>
	        ListOperations listOperations= redisTemplate.opsForList();
	        listOperations.leftPush(key, value);
	    }
	    public Object getList(){
	        //ListOperations可以理解为List<Object>
	        return redisTemplate.opsForList().leftPop("test-list");
	    }
	    public void setSet(String key ,Set<?> value){
	        SetOperations setOperations= redisTemplate.opsForSet();
	        setOperations.add(key, value);
	    }
	    public Object getSet(String key){
	        return redisTemplate.opsForSet().members(key);
	    }


	    public void setHash(String key ,Map<String,?> value){
	        HashOperations hashOperations = redisTemplate.opsForHash();
	        hashOperations.putAll(key,value);
	    }
	    public Object getHash(String key){
	        return redisTemplate.opsForHash().entries(key);
	    }


	    public void delete(String key){
	        redisTemplate.delete(key);
	    }
}